<?php 
	$color = GoodsTagsModel::getColor();
	//获取此分类下的推荐子分类
	$children = GoodsCateModel::model()->find(array(
		'site_id' 			=> SITE_ID,
		'parent' 			=> $this->cate_id,
		'goods_cate_flags' 	=> 0  //首页推荐
	), 'name', 0, 5, array('rank'=>1));
?>
<div class="<?php echo $this->full_class ?>" id="<?php echo $this->id ?>">
	<h3 style="color:<?php echo $color?>"><?php echo $this->title?></h3>
	<ul class="titles">
		<li cate="discount_goods" class="selected"><h4>特价商品</h4></li>
		<?php foreach ($children as $cate){?>
		<li cate="<?php echo $cate['_id'] ?>"><h4><?php echo $cate['name']?></h4></li>
		<?php }?>
	</ul>
	<b class="pointer"></b>
	<div class="more">
		<a href="<?php echo GoodsCateModel::getUrl($this->cate_id)?>">更多...</a>
	</div>
	<!-- 其下所有子分类 -->
	<div class="sub_cate_list">
		<?php 
			$sub_cates = GoodsCateModel::model()->find(array('parent'=>$this->cate_id, 'site_id'=>SITE_ID), null, 0, 30, array('rank'=>1));
			foreach ($sub_cates as $sub_cate_id=>$sub_cate){
				echo CHtml::link($sub_cate['name'], GoodsCateModel::getUrl($sub_cate));
			}
			//获取分类广告
			if(isset($this->cate['ads']['1'])){
				$ad_id = $this->cate['ads']['1'];
				$this->widget('application.widget.ad.AdWidget', array(
					'ad_id' 	=> $ad_id,
					'thumb' 	=> '180x180',
				));
			}
		?>
		
	</div>
	<ul class="goods_list selected" cate="discount_goods">
		<?php
		if(!empty($this->goods_list)){
			list($width, $height) = explode('x', $this->thumb);
			$no_picture = CommonHelper::get_thumb(NO_PICTURE, $this->thumb);
			foreach ($this->goods_list as $goods){
				if(isset($goods['main_picture']) && !empty($goods['main_picture']) && is_string($goods['main_picture'])){
					$main_picture = CommonHelper::get_thumb($goods['main_picture'], $this->thumb);
				}else{
					$main_picture = $no_picture;
				}
				$price = 0;
				if(isset($goods['price'])){
					$price = floatval($goods['price']);
				}
				
				$market_price = 0;
				if(isset($goods['market_price']) && !empty($goods['market_price'])){
					$market_price = floatval($goods['market_price']);
				}
				$url = GoodsModel::getUrl($goods);
		?>
		<li>
			<?php 
				echo CHtml::link(CHtml::image($main_picture, $goods['name'], array('class'=>'auto_img')), $url, array('class'=>'img', 'style'=>"width:{$width}px;height:{$height}px;"));
			?>
			<br>
			<div class="info">
			<?php echo CHtml::tag('h6', array(), CHtml::link($goods['name'], $url))?>
			<p>商城价：￥<?php echo number_format($price, 2)?></p>
			<?php if($market_price > 0){?>
			市场价：<del>￥<?php echo number_format($market_price, 2)?></del>
			<?php }?>
			</div>
		</li>
		<?php 
			}
		}
		?>
	</ul>
	
	<?php 
	//推荐子分类及商品展示
	foreach ($children as $cid=>$cate){
		//查询其下商品
		$fl = 'name,main_picture,price,specs,market_price';
		$condition = array(
			'status' 		=> GoodsModel::STATUS_ON_SALE,
			'site_id' 		=> SITE_ID, 
			'goods_flag' 	=> 1, //首页推荐
			'cate' 			=> $cid
		);

		$goods_list = GoodsModel::model()->find($condition, $fl, 0, 4, array('rank'=>1));		
	?>
	<ul class="goods_list" cate="<?php echo $cid?>">
		<?php
		if(!empty($goods_list)){
			list($width, $height) = explode('x', $this->thumb);
			$no_picture = CommonHelper::get_thumb(NO_PICTURE, $this->thumb);
			foreach ($goods_list as $goods){
				if(isset($goods['main_picture']) && !empty($goods['main_picture']) && is_string($goods['main_picture'])){
					$main_picture = CommonHelper::get_thumb($goods['main_picture'], $this->thumb);
				}else{
					$main_picture = $no_picture;
				}
				$price = 0;
				if(isset($goods['price'])){
					$price = floatval($goods['price']);
				}
				
				$market_price = 0;
				if(isset($goods['market_price']) && !empty($goods['market_price'])){
					$market_price = floatval($goods['market_price']);
				}
				$url = GoodsModel::getUrl($goods);
		?>
		<li>
			<?php 
				echo CHtml::link(CHtml::image($main_picture, $goods['name'], array('class'=>'auto_img')), $url, array('class'=>'img', 'style'=>"width:{$width}px;height:{$height}px;"));
			?>
			<br>
			<div class="info">
			<?php echo CHtml::tag('h6', array(), CHtml::link($goods['name'], $url))?>
			<p>商城价：￥<?php echo number_format($price, 2)?></p>
			<?php if($market_price > 0){?>
			市场价：<del>￥<?php echo number_format($market_price, 2)?></del>
			<?php }?>
			</div>
		</li>
		<?php 
			}
		}
		?>
	</ul>
	<?php }
	
		//品牌展示
		$color = GoodsTagsModel::getColor();
	?>
	<ul class="brand_list">
		<?php 
			$brands = BrandModel::model()->find(array(
				'site_id' 		=> SITE_ID,
				'cate' 			=> $this->cate_id,
				'brand_flags' 	=> 0 	//推荐
			), 'main_picture,name', 0, 10, array('rank'=>1));
			foreach ($brands as $brand_id=>$brand){
		?>
		<li>
			<a href="/brand/<?php echo $brand_id?>"><?php echo CHtml::image($brand['main_picture'], $brand['name'])?></a>
		</li>
		<?php 
			}
		?>
		
	</ul>
</div>